#include <iostream>
#include <utility>
#include <vector>
#include <thread>
#include <sstream>

#include "device_thread_manager.h"
#include "spdlog/spdlog.h"

namespace ai::facial_recognition {
    DeviceThreadManager::DeviceThreadManager() {

    }
    DeviceThreadManager::~DeviceThreadManager() {

    }

    template <class Function, class... Args>
    void DeviceThreadManager::startThread(Function&& f, Args&&... args) {
        threads.emplace_back(std::forward<Function>(f), std::forward<Args>(args)...);
    }

    void DeviceThreadManager::waitForAll() {
        for (auto& t : threads) {
            std::stringstream ss_id;
            ss_id << t.get_id();
            t.join();

            spdlog::info("thread {0:s} joined", ss_id.str());
        }
    }

}